package com.example.Mapper;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.example.domain.Cart;
import com.example.domain.CartVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface CartMapper extends BaseMapper<Cart> {

    @Select("SELECT cid,uid,pid,t_cart.price,t_cart.num,t_product.num AS numCount,t_product.title,t_product.price*t_cart.num AS realPrice,t_product.image \n" +
            "FROM t_cart LEFT JOIN t_product ON t_cart.pid=t_product.id where t_cart.uid=#{uid} ORDER BY t_cart.created_time DESC;")
    List<CartVO> PageCartVO(Long uid);

    //根据集合获取购物车+商品相关信息
    @Select("<script>" +
            "SELECT cid,uid,pid,t_cart.price,t_cart.num,t_product.num AS numCount,t_product.title,t_product.price*t_cart.num AS realPrice,t_product.image \n" +
            "FROM t_cart LEFT JOIN t_product ON t_cart.pid=t_product.id" +
                "<where>" +
                    "t_cart.cid in" +
                    "<foreach item='cid' collection='list' open='(' separator=',' close=')'>" +
                        "#{cid}" +
                    "</foreach>" +
                "</where>" +
            "ORDER BY t_cart.created_time DESC;" +
            "</script>")
    List<CartVO> getListCids(List<Long> cids);
}
